/*
 * @Author: OBKoro1
 * @Date: 2022-07-06 10:29:29
 * @LastEditors: OBKoro1
 * @LastEditTime: 2022-07-06 15:01:08
 * @FilePath: \onemodeSWJ\src\utils\publicFunction.ts
 * @Description:
 *
 * Copyright (c) 2022 by 用户/公司名, All Rights Reserved.
 */

let timer = {};

// 配置全局公共方法使用
// 防抖函数
const throttle = (name, fn, time = 100) => {
  if (timer[name] != null) {
    clearTimeout(timer[name]);
  }
  timer[name] = setTimeout(() => {
    // 使用call改变fn函数this指向
    fn.call(this);
  }, time);
};

export default {
  install: (app: any) => {
    app.config.globalProperties.throttle = throttle;
  },
};
